local guidao = fk.CreateSkill {
  name = "klmou__guidao",
}

Fk:loadTranslationTable{
  ["klmou__guidao"] = "鬼道",
  [":klmou__guidao"] = "当其他角色的判定牌生效前，你可以查看一名角色区域内的一张牌代替之，若如此做，你获得判定牌、其摸一张牌。",
  ["#klmou__guidao-target"] = "发动鬼道，选择一名角色，观看并用其区域内的一张牌代替 %dest 的[%arg]判定牌！",
  ["#klmou__guidao-ask"] = "鬼道：用一张牌代替 %dest 的[%arg]判定，然后你获得判定牌",

  ["$klmou__guidao1"] = "神鬼之道，凡人不可及！",
  ["$klmou__guidao2"] = "鬼道轮回，非大化不可逆之！",
}

local HX = require "packages.konglong.hxfs2"

guidao:addEffect(fk.AskForRetrial, {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(guidao.name) and not table.every(player.room.alive_players, function (p) return p:isAllNude() end)
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local tos = table.filter(player.room.alive_players, function (p) return not p:isAllNude() end)
    if #tos == 0 then return end
    local to = room:askToChoosePlayers(player, {
      targets = tos,
      prompt = "#klmou__guidao-target::"..target.id .. ":" .. data.reason,
      min_num = 1,
      max_num = 1,
      cancelable = true,
      skill_name = guidao.name,
    })
    if #to == 0 then return end
    local card = HX.askToChooseCards(room, player, {
      flag = "hej",
      min = 1,
      max = 1,
      target = to[1],
      skill_name = guidao.name,
      prompt = "#klmou__guidao-ask::"..target.id .. ":" .. data.reason,
    })
    if #card > 0 then
      event:setCostData(self, { to = to[1], card = card[1] })
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local card = data.card
    player.room:changeJudge{
      card = Fk:getCardById(event:getCostData(self).card),
      player = player,
      data = data,
      skillName = guidao.name,
    }
    if card then
      player.room:obtainCard(player, card, true, fk.ReasonPrey, player, guidao.name)
      event:getCostData(self).to:drawCards(1, guidao.name)
    end
  end,
})


return guidao
